import messageUtil from "../utils/messageUtil"
import httpUtil from "../utils/httpUtil"
import logApi from "./logApi"

// #ifdef MP-ALIPAY

function getZfbAuthorizeMobile(encryptedData, sign, successHandler, errHandler) {
	let params = {
		appid: '2021004115620105',
		encryptedData: encryptedData,
		sign: sign,
	}
	logApi.addLog('自动获取手机号解密发送前，参数：' + JSON.stringify(params))
	httpUtil.post("/api/rf/openSignCj", params, res => {
		logApi.addLog('自动获取手机号解密返回，参数：' + JSON.stringify(params) + '。返回：' + JSON.stringify(res))
		if (successHandler) {
			console.log('getAuthorizeMobile', res.data)
			successHandler(res.data)
		}

	}, err => {
		logApi.addLog('自动获取手机号解密错误，参数：' + JSON.stringify(params) + '。错误信息：' + JSON.stringify(err))
		if (errHandler) {
			errHandler(err)
		}
	})
}
// #endif

/**
 * 通过手机号获取运营商
 */
const getYys = (mobile, successCallBack, errorCallBack) => {
	httpUtil.postReturnSource('/api/jssxk/getYys', {
		mobile
	}, res => {
		// {"code": 0,"reason": "Succ","result": {"Mobile": "13880104834","Province": "四川","City": "成都","Isp": "中国移动"}}
		console.log('getOperator', res)
		if (res.reason != 'Succ' || res.code != 0) {
			messageUtil.showFail('获取运营商失败，请于管理员联系')
			return;
		}
		successCallBack(res.result);
	}, err => {
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}

export default {
	getYys,
	// #ifdef MP-ALIPAY
	getZfbAuthorizeMobile,
	// #endif
}